// ml:run = $bin < input
#include <iostream>
#include <algorithm>

using ll = long long;
int a[200], b[200];
ll l, r;
int l1, l2;

void get(int a[], int & len, ll x)
{
    while (x) {
        a[len++] = x & 1;
        x /= 2;
    }
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    int T; std::cin >> T;
    while (T--) {
        std::cin >> l >> r;
        if (l == r) { std::cout << l << "\n"; continue; }
        l1 = l2 = 0;
        get(a, l1, l);
        get(b, l2, r);

        if (l1 != l2) {
            std::cout << ((1ll) << std::max(l1, l2)) - 1 << "\n";
        } else {
            int i = l1 - 1;
            for (; i >= 0; i--)
                if (a[i] != b[i]) break;
            for (int j = i - 1; j >= 0; j--) b[j] = 1;
            ll ans = 0;
            for (int i = 0; i < l1; i++)
                ans += ((1ll) << i)* b[i];
            std::cout << ans << "\n";
        }
    }
}

